package view;

import java.awt.Color;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
/**
 * this class is Graphic user interface of add new Category which extends AbstractGUI
 * @author jacob
 *
 */
public class CategoryGui extends AbstractGUI{
	
	private JTextField nameText = null;
	private JLabel name1 = null;
	private JButton addB = null;
	private JLabel warningMes = null;
	
/**
 * constructor 
 * this constructor add all the Label, Button,TextField to the Frame
 */
	public CategoryGui(){
		
		getContentPane().add( getNameText());
		getContentPane().add(getName1());
		getContentPane().add(getAdd());
		getContentPane().add(getBackButton());
		getContentPane().add(getWarningMes());
		
		getContentPane().setBackground(Color.LIGHT_GRAY);
		
		this.setLayout(null);
		this.setTitle("add Category");
		this.setBounds(500, 200, 350, 250);
	//	this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		this.setVisible(true);
		this.setResizable(false);
		
	}

/*****************************************Getters and Setters of Label, Button,TextField *****************************/
	public JTextField getNameText() {
		if(nameText == null){
			nameText = new JTextField("");
			nameText.setBounds(130, 50, 180, 25);
			nameText.setColumns(10);
			
		}
		return nameText;
	}
  
	public String getText() {
		return nameText.getText();	
	}
	
	public JLabel getName1() {
		if(name1 == null){
			name1 = new JLabel("Category name:");
			name1.setBounds(30, 50, 140, 25);
		}
		return name1;
	}


	public JButton getAdd() {
		if(addB == null){
			addB = new JButton("Add");
			addB.setBounds(200, 170, 80, 25);
			
		}
		return addB;
	}
	
	public JButton getBackButton() {
		if(backButton == null){
			backButton = new JButton("back");
			backButton.setBounds(75, 170, 80, 25);
		}
		return backButton;
	}
	
	public JLabel getWarningMes() {
		if(warningMes == null){
			warningMes = new JLabel("This Category is already exist");
			warningMes.setForeground(Color.RED);
			warningMes.setBounds(75, 130, 200, 25);
			warningMes.setVisible(false);
		}	
		return warningMes;
	}
/**
 * set Warning Massage on gui
 * @param mes
 */

	public void setWarningMes(String mes) {
		warningMes.setText(mes);
		warningMes.setVisible(true);
	}
	public void setWarningMesFalse(){
		warningMes.setVisible(false);
	}
	/**
	 * add to Add button ActionListener
	 * @param listener
	 */
	public void addAddActionListener(ActionListener listener){
		addB.addActionListener(listener);
	}
}
